<template>
	<view class="uni-tabbar">
		<view class="uni-tabbar__item" v-for="(item,index) in tabbar" :key="index" @tap="changeTab(item)">
			<!-- <view class="uni-tabbar__bd">
				<view class="uni-tabbar__icon">
					<image v-if="item.pagePath == pagePath" class="icon-img" mode="aspectFit" :src="item.selectedIconPath"></image>
					<image v-else class="icon-img" mode="aspectFit" :src="item.iconPath"></image>
				</view>
			</view> -->
			<view class="uni-tabbar__label" :class="{'active': item.pagePath == pagePath}">
				{{item.text}}
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		props: {
			pagePath: String
		},
		data() {
			return {
				page: 'contact',
				showPage: false,
				containerHeight: 400,
				tabbar: [
					//动态切换的菜单，先隐藏，动态插入
				]
			};
		},
		mounted() {
	
				console.log('切换权限')
				console.log(uni.getStorageSync('cdtype'))
		        console.log('切换权限')
		        if(uni.getStorageSync('cdtype')==5){
		        	this.tabbar.splice(0, 0, {
		        		"pagePath": "/pages/index/index",
		        		"text": "首页"
		        	},{
		        		"pagePath": "/pages/shoquan/shoquan",
		        	
		        		"text": "授权"
		        	}, {
		        		"pagePath": "/pages/sjcx/sjcx",
		        				
		        		"text": "数据查询"
		        	}, 
		        	{
		        		"pagePath": "/pages/my/my",
		        				
		        		"text": "个人中心"
		        	})
		        }else if(uni.getStorageSync('cdtype')==2){
		        	this.tabbar.splice(0, 0, {
		        		"pagePath": "/pages/index/index",
		        			
		        		"text": "首页"
		        	}
					, {
		        		"pagePath": "/pages/shoquan/detail",
		        	
		        		"text": "预约"
		        	},{
						"pagePath": "/pages/shoquan/appoint",
					
						"text": "查看预约"
					},
		        	{
		        		"pagePath": "/pages/my/my",
		        				
		        		"text": "个人中心"
		        	})
		        }else if(uni.getStorageSync('cdtype')==1){
					this.tabbar.splice(0, 0, {
						"pagePath": "/pages/index/index",
							
						"text": "预约"
					},
					{
						"pagePath": "/pages/shoquan/sjckyuylist",
					
						"text": "查看预约"
					},
					{
						"pagePath": "/pages/my/my",
								
						"text": "个人中心"
					})
				} else if(uni.getStorageSync('cdtype')==4){
					this.tabbar.splice(0, 0, {
						"pagePath": "/pages/index/index",
							
						"text": "首页"
					},
					{
						"pagePath": "/pages/shoquan/pzcdlh",
					
						"text": "授权"
					},
					{
						"pagePath": "/pages/my/my",
								
						"text": "个人中心"
					})
				}else if(uni.getStorageSync('cdtype')==3){
					this.tabbar.splice(0, 0, {
						"pagePath": "/pages/index/index",
							
						"text": "首页"
					},
					{
						"pagePath": "/pages/shoquan/lihuo",
					
						"text": "理货"
					},
					
					{
						"pagePath": "/pages/sjcx/lhysjcx",
					
						"text": "数据查询"
					},
					{
						"pagePath": "/pages/my/my",
								
						"text": "个人中心"
					})
				}else if(uni.getStorageSync('cdtype')==6){
					this.tabbar.splice(0, 0, {
						"pagePath": "/pages/index/index",
						"text": "首页"
					},
					{
						"pagePath": "/pages/lshz/lshz",
					
						"text": "预约"
					},
					{
						"pagePath": "/pages/lshz/lshzyuy",
					
						"text": "查看预约"
					},
					{
						"pagePath": "/pages/lshz/lhcx",
								
						"text": "数据查询"
					}, 
					{
						"pagePath": "/pages/my/my",
								
						"text": "个人中心"
					})
				}else if(uni.getStorageSync('cdtype')==7){
					this.tabbar.splice(0, 0, {
						"pagePath": "/pages/index/index",
							
						"text": "首页"
					},
					{
						"pagePath": "/pages/shy/shy",
					
						"text": "数据查询"
					},
					{
						"pagePath": "/pages/shy/shymy",
								
						"text": "个人中心"
					})
				}
				else{
					this.tabbar.splice(0, 0, {
						"pagePath": "/pages/index/index",
						"text": "首页"
					},
					{
						"pagePath": "/pages/my/my",
						"text": "个人中心"
					})
				}
		 },
		watch: {
			pagePath: {
				handler(val) {
					console.log('pagePath监听===val', val)
				},
				immediate: true
			}
		},
		methods: {
			changeTab(item) {
				this.page = item.pagePath;
				// 使用reLaunch关闭全部的页面，打开新的栏目页面
				uni.reLaunch({
					url: this.page
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.uni-tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 999;
		width: 100%;
		display: flex;
		justify-content: space-around;
		height: 98upx;
		padding: 16upx 0;
		box-sizing: border-box;
		border-top: solid 1upx #ccc;
		background-color: #fff;
		box-shadow: 0px 0px 17upx 1upx rgba(206, 206, 206, 0.32);

		.uni-tabbar__item {
			display: block;
			height: 49px;
			line-height: 49px;
			font-size: 20upx;
			text-align: center;
			width: 25%;
		}

		.uni-tabbar__icon {
			height: 24px;
			line-height: 24px;
			text-align: center;
		}

		.icon {
			display: inline-block;
		}

		.uni-tabbar__label {
			line-height: 49px;
			height: 49px;
			font-size: 30upx;
			color: #999;

			&.active {
				color: #3c77b7;
			}
		}

		.icon-img {
			height: 24px;
			width: 24px;
		}
	}
</style>